package export.bullet
{
	import base.BaseHero;
	
	import com.dusk.util.McUtil;
	import com.greensock.TweenMax;
	
	import export.mapPrefab.wall.ThroughWall;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	
	public class ThroughWallBullet extends ThroughWall
	{
		
		public function ThroughWallBullet(param1:int)
		{
			super();
			this.velocity.x = param1;
			if (this.velocity.x > 0)
			{
				this.moveDirect = 1;
			}
			else if (this.velocity.x < 0)
			{
				this.moveDirect = 2;
			}
			else
			{
				this.moveDirect = 3;
			}
			this.isThroughWall = new MovieClip();
			this.isThroughWall.name = "isThroughWall";
			this.addChild(this.isThroughWall);
			this.visible = false;
			this.stopCounts = gc.frameClips * 6;
		}
		
		private var isStop:Boolean = false;
		private var moveDirect:int = 1;
		private var totalCount:int;
		private var stopCount:int;
		private var swordEffect:SpecialEffectBullet;
		private var stopCounts:uint;
		
		override public function step():void
		{
			var temp:* = undefined;
			var heroArray:Array = null;
			var i:int = 0;
			var bh:BaseHero = null;
			temp = undefined;
//			if (this.userData)
//			{
//				if (this.speed.x > 0)
//				{
//					if (this.userData.transform.matrix.a < 0)
//					{
//						McUtil.flipHorizontal(this.userData, 1);
//					}
//				}
//				else if (this.speed.x < 0)
//				{
//					if (this.userData.transform.matrix.a > 0)
//					{
//						McUtil.flipHorizontal(this.userData, -1);
//					}
//				}
//			}
			if (!this.isStop)
			{
//				if (this.userData)
//				{
//					this.userData.visible = false;
//				}
				heroArray = gc.team.getHeroArray();
				i = 0;
				while (i < heroArray.length)
				{
					bh = heroArray[i] as BaseHero;
					if (bh.standInObj == this)
					{
						this.isStop = true;
						temp = {};
						TweenMax.to(temp, 0.5, {
							"y"         : temp.y + 10,
							"onComplete": function ():*
							{
								TweenMax.to(temp, 0.5, {"y": Number(temp.y) - 4});
							}
						});
						break;
					}
					i++;
				}
				if (this.moveDirect == 1)
				{
					this.velocity.x -= 0.5;
				}
				else if (this.moveDirect == 2)
				{
					this.velocity.x += 0.5;
				}
				else if (this.moveDirect == 3)
				{
					this.velocity.x = 0;
				}
			}
			else
			{
				if (this.swordEffect)
				{
					this.swordEffect.destroy();
				}
//				if (this.userData)
//				{
//					this.userData.visible = true;
//				}
				++this.stopCount;
				this.velocity.x = 0;
			}
			super.step();
			++this.totalCount;
			if (this.isStop)
			{
				if (this.stopCount >= this.stopCounts)
				{
					this.dispatchEvent(new Event("destroy"));
					this.destroy();
				}
			}
			else if (this.totalCount >= gc.frameClips * 8)
			{
				this.dispatchEvent(new Event("destroy"));
				this.destroy();
			}
		}
		
		override public function destroy():void
		{
			super.destroy();
		}
		
		public function setStopDoubleCount():void
		{
			this.stopCounts = gc.frameClips * 12;
		}
		
		public function setSwordEffect(param1:SpecialEffectBullet):void
		{
			this.swordEffect = param1;
		}
	}
}
